package eSchool.GUI.Controls;

import eSchool.Utils.TextHelper;
import javax.swing.table.TableModel;

public class panDataGrid extends JPanelExtended {

    public panDataGrid() {
        initComponents();
        panSearchGrid1.setVisible(true);
        panSearchGrid1.setEnabled(true);
        panSearchGrid1.setEventListner(this);

        //dtGPesquisa.consDataGrid(cabecalho, largura, null);
    }

    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlDataGrid = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        dtGPesquisa = new eSchool.GUI.Controls.DataGrid();
        panSearchGrid1 = new eSchool.GUI.Controls.panSearchGrid();

        setLayout(new java.awt.BorderLayout());

        dtGPesquisa.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        dtGPesquisa.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                dtGPesquisaMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(dtGPesquisa);

        javax.swing.GroupLayout pnlDataGridLayout = new javax.swing.GroupLayout(pnlDataGrid);
        pnlDataGrid.setLayout(pnlDataGridLayout);
        pnlDataGridLayout.setHorizontalGroup(
            pnlDataGridLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 462, Short.MAX_VALUE)
            .addComponent(panSearchGrid1, javax.swing.GroupLayout.DEFAULT_SIZE, 462, Short.MAX_VALUE)
        );
        pnlDataGridLayout.setVerticalGroup(
            pnlDataGridLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlDataGridLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(panSearchGrid1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 211, Short.MAX_VALUE))
        );

        add(pnlDataGrid, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents

    public void setSearchVisible(boolean enable){
        panSearchGrid1.setVisible(enable);
    }
    
    public void setSearchEnabled(boolean enable){
        panSearchGrid1.setEnabled(enable);
    }
    
    
    public void setDataSource(TableModel tableModel){
        dtGPesquisa.setDataSource(tableModel);
        panSearchGrid1.setDataSource(tableModel);
    }
    
    public void DataBind() throws Exception{
        dtGPesquisa.dataBind();
        panSearchGrid1.dataBind();
    }
    
    public void setDataGridColumnIdentifiers(DataGridColumnIdentifiers identifiers){
        dtGPesquisa.setColumnIdentifiers(identifiers);
    }
    
    @Override
    public void SearchButtonClickEvent(Object Sender, Object obj) {
        eventListner.SearchButtonClickEvent(this, obj);
    }
    
    public String getSelectRowValue(int col){
            if(dtGPesquisa.getValueAt(dtGPesquisa.getSelectedRow(), 0) != null)
               return dtGPesquisa.getValueAt(dtGPesquisa.getSelectedRow(), col).toString();
            
            return TextHelper.EmptyString;
    }
    
    private void dtGPesquisaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_dtGPesquisaMouseClicked
        if (evt.getClickCount() == 2) {
            eventListner.GridDoubleClickEvent(this.dtGPesquisa, dtGPesquisa.getSelectedRow());
        }
    }//GEN-LAST:event_dtGPesquisaMouseClicked
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private eSchool.GUI.Controls.DataGrid dtGPesquisa;
    private javax.swing.JScrollPane jScrollPane1;
    private eSchool.GUI.Controls.panSearchGrid panSearchGrid1;
    private javax.swing.JPanel pnlDataGrid;
    // End of variables declaration//GEN-END:variables
    
   
}
